﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic; 	


public class TILE : MonoBehaviour {
	GameObject score;
	int LV;
	public GameObject Wall;
	public GameObject Player;
	public GameObject Box;
	public GameObject Goods;
	int[,,] tiles=new int[3,9,9]{
		{{0,0,1,1,1,0,0,0,0},
			{0,0,1,3,1,0,0,0,0},
			{0,0,1,0,1,1,1,1,0},
			{1,1,1,2,4,2,3,1,0},
			{1,3,0,2,0,1,1,1,0},
			{1,1,1,1,2,1,0,0,0},
			{0,0,0,1,3,1,0,0,0},
			{0,0,0,1,1,1,0,0,0},
			{0,0,0,0,0,0,0,0,0}},
	   {{0,0,0,1,1,1,1,0,0},   
		{0,1,1,1,0,4,1,0,0},
	    {0,1,0,0,2,0,1,0,0},
		{1,1,0,1,0,1,1,1,0},
		{1,0,0,1,0,1,3,1,0},
		{1,0,1,0,0,2,3,1,0},
		{1,0,2,0,0,0,3,1,0},
		{1,1,1,1,1,1,1,1,0},
		{0,0,0,0,0,0,0,0,0}},
		     {{0,0,0,0,1,1,1,1,1},
			  {0,0,0,0,1,0,0,4,1},
			  {1,1,1,0,1,2,2,0,1},
			  {1,3,1,0,1,0,2,0,1},
			  {1,3,1,1,1,0,1,1,1},
			  {1,3,0,0,1,0,1,1,0},
		  	  {1,0,0,1,0,0,0,1,0},
			  {1,1,1,1,0,0,0,1,0},
			  {0,0,0,1,1,1,1,1,0}}};
	int[,] tiles1 =new int[8,8]{{0,0,0,1,1,1,1,0},
		{0,1,1,1,0,0,1,0},
		{0,1,0,0,2,0,1,0},
		{1,1,0,1,0,1,1,1},
		{1,0,0,1,0,1,3,1},
		{1,0,1,0,0,2,3,1},
		{1,0,2,0,0,0,3,1},
		{1,1,1,1,1,1,1,1}}; 
	int[,] tiles2 = new int[9,9]{{0,0,0,0,1,1,1,1,1},
		{0,0,0,0,1,0,0,0,1},
		{1,1,1,0,1,2,2,0,1},
		{1,3,1,0,1,0,2,0,1},
		{1,3,1,1,1,0,1,1,1},
		{1,3,0,0,1,0,1,1,0},
		{1,0,0,1,0,0,0,1,0},
		{1,1,1,1,0,0,0,1,0},
		{0,0,0,1,1,1,1,1,0}};
	void ct(){
		for (int i=0; i<9;i++) {
			for(int j=0;j<9;j++){
			    if(tiles[LV,i,j]==1){
				GameObject wall= (GameObject)Instantiate(Wall,new Vector3(i,0,j),Quaternion.identity);
				}
				if(tiles[LV,i,j]==2){
					GameObject box = (GameObject)Instantiate(Box,new Vector3(i,0,j),Quaternion.identity);
				}
				if(tiles[LV,i,j]==3){
					GameObject goods = (GameObject)Instantiate(Goods,new Vector3(i,0,j),Quaternion.identity);
					Gamemanager.Totalscore++;
				}
				if(tiles[LV,i,j]==4){
					Player.transform.position=new Vector3(i,0,j);
				}
			}

		}
	}


	// Use this for initialization
	void Start () {
		LV=GameObject.Find("game manager").GetComponent<Gamemanager>().Level-1;
		print ("level");
		score = GameObject.Find ("score");
		ct ();
	
	}
	
	// Update is called once per frame
	void Update () {
		score.GetComponent<Text> ().text="SCORE "+Gamemanager.CurrentScore+"/"+Gamemanager.Totalscore;


 }

}